package com.lagou.utils;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 *
 * @author tengfei wang
 * @version 1.0
 * @date Created in 2020/8/31
 */
public class DruidsUtils {

    private DruidsUtils() {
    }

    private static final DruidsUtils instance = new DruidsUtils();

    public static DruidsUtils getInstance() {
        return instance;
    }

    public Connection getConnection() {
        Connection connection = null;
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        druidDataSource.setUrl("jdbc:mysql://localhost:3306/lagou");
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("root");
        try {
            connection = druidDataSource.getConnection();
        } catch (SQLException e) {
            System.out.println("获取数据库连接异常");
            e.printStackTrace();
        }
        return connection;
    }
}
